﻿using UnityEngine;
using System.Collections;

public class HealthScript : MonoBehaviour {

	// Use this for initialization
	public int hp = 1;

	public bool isEnemy = true;

	public void Damage(int damageCount){
		hp -= damageCount;
		if (hp <= 0) {
			Destroy(gameObject);
		}

	}

	void OnTriggerEnter2D(Collider2D otherCollider)
	{
		ShotScript shot =
			otherCollider.gameObject.GetComponent<ShotScript> ();
			if (shot != null) {
			if (shot.isEnemyShot != isEnemy) {
				Damage (shot.damage);
				Destroy (shot.gameObject);
			}
		}
	}
}


